import type { Component } from 'vue';
import type { ComponentType } from './types/componentType';

/**
 * Component list, register here to setting it in the form
 */

import * as AntdComponents from 'ant-design-vue/es/components';

import ApiRadioGroup from '/@/components/Form/src/components/ApiRadioGroup.vue';
import RadioButtonGroup from '/@/components/Form/src/components/RadioButtonGroup.vue';
import ApiSelect from '/@/components/Form/src/components/ApiSelect.vue';
import ApiTree from '/@/components/Form/src/components/ApiTree.vue';
import ApiTreeSelect from '/@/components/Form/src/components/ApiTreeSelect.vue';
import ApiCascader from '/@/components/Form/src/components/ApiCascader.vue';
import ApiTransfer from '/@/components/Form/src/components/ApiTransfer.vue';
import { BasicUpload, Uploader } from '/@/components/Upload';

import { CountdownInput } from '/@/components/CountDown';

const componentMap = new Map<ComponentType, Component>();

componentMap.set('ApiSelect', ApiSelect);
componentMap.set('ApiTree', ApiTree);
componentMap.set('ApiTreeSelect', ApiTreeSelect);
componentMap.set('ApiRadioGroup', ApiRadioGroup);

componentMap.set('Upload', BasicUpload);

componentMap.set('RadioButtonGroup', RadioButtonGroup);

componentMap.set('ApiCascader', ApiCascader);

componentMap.set('ApiTransfer', ApiTransfer);

// componentMap.set('StrengthMeter', StrengthMeter);

componentMap.set('InputCountDown', CountdownInput);

componentMap.set('Uploader', Uploader);

for (const key in AntdComponents) {
  const comp = AntdComponents[key];
  //组件没有name,跳过。比如Messasge.success
  if (!comp.name) {
    continue;
  }
  if (componentMap.has(comp.name)) {
    console.warn('组件已存在!!', comp.name, comp);
  } else {
    add(comp.name, comp);
  }
}

export function add(compName: ComponentType, component: Component) {
  componentMap.set(compName, component);
}

export function del(compName: ComponentType) {
  componentMap.delete(compName);
}

export { componentMap };
